using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VMSABWS
    {
        public DataRow Convert2MSABWS(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryMSABWS(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["MSAMANDANT"] = " ".PadRight(2 ); 
         dwReturn["MSAKTOKL"] = " ".PadRight(6 ); 
         dwReturn["MSAPRODKL"] = " ".PadRight(7 ); 
         dwReturn["MSAAENZL"] = " ".PadRight(0 ); 
         dwReturn["MSAAENB"] = " ".PadRight(8 ); 
         dwReturn["MSAAEND"] = " ".PadRight(0 ); 
         dwReturn["MSANEUB"] = " ".PadRight(8 ); 
         dwReturn["MSANEUD"] = " ".PadRight(0 ); 
         dwReturn["MSAAMONAT1"] = " ".PadRight(0 ); 
         dwReturn["MSAAMONAT2"] = " ".PadRight(0 ); 
         dwReturn["MSAAMONAT3"] = " ".PadRight(0 ); 
         dwReturn["MSAAMONAT4"] = " ".PadRight(0 ); 
         dwReturn["MSAAMONAT5"] = " ".PadRight(0 ); 
         dwReturn["MSAAPROZ1"] = " ".PadRight(0 ); 
         dwReturn["MSAAPROZ2"] = " ".PadRight(0 ); 
         dwReturn["MSAAPROZ3"] = " ".PadRight(0 ); 
         dwReturn["MSAAPROZ4"] = " ".PadRight(0 ); 
         dwReturn["MSAAPROZ5"] = " ".PadRight(0 ); 
         dwReturn["MSAEINGKZ"] = " ".PadRight(1 ); 
         dwReturn["MSARWMONAT1"] = " ".PadRight(0 ); 
         dwReturn["MSARWMONAT2"] = " ".PadRight(0 ); 
         dwReturn["MSARWMONAT3"] = " ".PadRight(0 ); 
         dwReturn["MSARWMONAT4"] = " ".PadRight(0 ); 
         dwReturn["MSARWMONAT5"] = " ".PadRight(0 ); 
         dwReturn["MSARWPROZ1"] = " ".PadRight(0 ); 
         dwReturn["MSARWPROZ2"] = " ".PadRight(0 ); 
         dwReturn["MSARWPROZ3"] = " ".PadRight(0 ); 
         dwReturn["MSARWPROZ4"] = " ".PadRight(0 ); 
         dwReturn["MSARWPROZ5"] = " ".PadRight(0 ); 
         dwReturn["MSAMINDALT"] = " ".PadRight(0 ); 
         dwReturn["MSAZEITRAUM"] = " ".PadRight(0 ); 
         dwReturn["MSAMANPROZ1"] = " ".PadRight(0 ); 
         dwReturn["MSAMANPROZ2"] = " ".PadRight(0 ); 
         dwReturn["MSAMANPROZ3"] = " ".PadRight(0 ); 
         dwReturn["MSAMANPROZ4"] = " ".PadRight(0 ); 
         dwReturn["MSAMANPROZ5"] = " ".PadRight(0 ); 
         dwReturn["MSAPROZVON1"] = " ".PadRight(0 ); 
         dwReturn["MSAPROZVON2"] = " ".PadRight(0 ); 
         dwReturn["MSAPROZVON3"] = " ".PadRight(0 ); 
         dwReturn["MSAPROZBIS1"] = " ".PadRight(0 ); 
         dwReturn["MSAPROZBIS2"] = " ".PadRight(0 ); 
         dwReturn["MSAPROZBIS3"] = " ".PadRight(0 ); 
         dwReturn["MSAMEINST"] = " ".PadRight(4 ); 
         dwReturn["MSAMBEWPR"] = " ".PadRight(1 ); 
         dwReturn["MSAINVBEWPR"] = " ".PadRight(1 ); 
         dwReturn["MSAKZBS"] = " ".PadRight(1 ); 
         dwReturn["MSAFILLER"] = " ".PadRight(45 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapMSABWS(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveMSABWS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryMSABWS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapMSABWS(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertMSABWS(dwLocal, ITXDBVERSION);
            }
            UpdateMSABWS(dwLocal);
        }
        public void InsertMSABWS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO MSABWS(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryMSABWS(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM MSABWS WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM MSABWS  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "MSABWS";
            Return = Result;
            return Return;
        }
        public void DeleteMSABWS(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM MSABWS   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateMSABWS(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE MSABWS SET "
                    +"MSAMANDANT= :MSAMANDANT,"
                    +"MSAKTOKL= :MSAKTOKL,"
                    +"MSAPRODKL= :MSAPRODKL,"
                    +"MSAAENZL= :MSAAENZL,"
                    +"MSAAENB= :MSAAENB,"
                    +"MSAAEND= :MSAAEND,"
                    +"MSANEUB= :MSANEUB,"
                    +"MSANEUD= :MSANEUD,"
                    +"MSAAMONAT1= :MSAAMONAT1,"
                    +"MSAAMONAT2= :MSAAMONAT2,"
                    +"MSAAMONAT3= :MSAAMONAT3,"
                    +"MSAAMONAT4= :MSAAMONAT4,"
                    +"MSAAMONAT5= :MSAAMONAT5,"
                    +"MSAAPROZ1= :MSAAPROZ1,"
                    +"MSAAPROZ2= :MSAAPROZ2,"
                    +"MSAAPROZ3= :MSAAPROZ3,"
                    +"MSAAPROZ4= :MSAAPROZ4,"
                    +"MSAAPROZ5= :MSAAPROZ5,"
                    +"MSAEINGKZ= :MSAEINGKZ,"
                    +"MSARWMONAT1= :MSARWMONAT1,"
                    +"MSARWMONAT2= :MSARWMONAT2,"
                    +"MSARWMONAT3= :MSARWMONAT3,"
                    +"MSARWMONAT4= :MSARWMONAT4,"
                    +"MSARWMONAT5= :MSARWMONAT5,"
                    +"MSARWPROZ1= :MSARWPROZ1,"
                    +"MSARWPROZ2= :MSARWPROZ2,"
                    +"MSARWPROZ3= :MSARWPROZ3,"
                    +"MSARWPROZ4= :MSARWPROZ4,"
                    +"MSARWPROZ5= :MSARWPROZ5,"
                    +"MSAMINDALT= :MSAMINDALT,"
                    +"MSAZEITRAUM= :MSAZEITRAUM,"
                    +"MSAMANPROZ1= :MSAMANPROZ1,"
                    +"MSAMANPROZ2= :MSAMANPROZ2,"
                    +"MSAMANPROZ3= :MSAMANPROZ3,"
                    +"MSAMANPROZ4= :MSAMANPROZ4,"
                    +"MSAMANPROZ5= :MSAMANPROZ5,"
                    +"MSAPROZVON1= :MSAPROZVON1,"
                    +"MSAPROZVON2= :MSAPROZVON2,"
                    +"MSAPROZVON3= :MSAPROZVON3,"
                    +"MSAPROZBIS1= :MSAPROZBIS1,"
                    +"MSAPROZBIS2= :MSAPROZBIS2,"
                    +"MSAPROZBIS3= :MSAPROZBIS3,"
                    +"MSAMEINST= :MSAMEINST,"
                    +"MSAMBEWPR= :MSAMBEWPR,"
                    +"MSAINVBEWPR= :MSAINVBEWPR,"
                    +"MSAKZBS= :MSAKZBS,"
                    +"MSAFILLER= :MSAFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("MSAMANDANT", OracleType.NVarChar).Value = dwData["MSAMANDANT"].ToString(); 
          or1.Parameters.Add("MSAKTOKL", OracleType.NVarChar).Value = dwData["MSAKTOKL"].ToString(); 
          or1.Parameters.Add("MSAPRODKL", OracleType.NVarChar).Value = dwData["MSAPRODKL"].ToString(); 
          or1.Parameters.Add("MSAAENZL", OracleType.NVarChar).Value = dwData["MSAAENZL"].ToString(); 
          or1.Parameters.Add("MSAAENB", OracleType.NVarChar).Value = dwData["MSAAENB"].ToString(); 
          or1.Parameters.Add("MSAAEND", OracleType.NVarChar).Value = dwData["MSAAEND"].ToString(); 
          or1.Parameters.Add("MSANEUB", OracleType.NVarChar).Value = dwData["MSANEUB"].ToString(); 
          or1.Parameters.Add("MSANEUD", OracleType.NVarChar).Value = dwData["MSANEUD"].ToString(); 
          or1.Parameters.Add("MSAAMONAT1", OracleType.NVarChar).Value = dwData["MSAAMONAT1"].ToString(); 
          or1.Parameters.Add("MSAAMONAT2", OracleType.NVarChar).Value = dwData["MSAAMONAT2"].ToString(); 
          or1.Parameters.Add("MSAAMONAT3", OracleType.NVarChar).Value = dwData["MSAAMONAT3"].ToString(); 
          or1.Parameters.Add("MSAAMONAT4", OracleType.NVarChar).Value = dwData["MSAAMONAT4"].ToString(); 
          or1.Parameters.Add("MSAAMONAT5", OracleType.NVarChar).Value = dwData["MSAAMONAT5"].ToString(); 
          or1.Parameters.Add("MSAAPROZ1", OracleType.NVarChar).Value = dwData["MSAAPROZ1"].ToString(); 
          or1.Parameters.Add("MSAAPROZ2", OracleType.NVarChar).Value = dwData["MSAAPROZ2"].ToString(); 
          or1.Parameters.Add("MSAAPROZ3", OracleType.NVarChar).Value = dwData["MSAAPROZ3"].ToString(); 
          or1.Parameters.Add("MSAAPROZ4", OracleType.NVarChar).Value = dwData["MSAAPROZ4"].ToString(); 
          or1.Parameters.Add("MSAAPROZ5", OracleType.NVarChar).Value = dwData["MSAAPROZ5"].ToString(); 
          or1.Parameters.Add("MSAEINGKZ", OracleType.NVarChar).Value = dwData["MSAEINGKZ"].ToString(); 
          or1.Parameters.Add("MSARWMONAT1", OracleType.NVarChar).Value = dwData["MSARWMONAT1"].ToString(); 
          or1.Parameters.Add("MSARWMONAT2", OracleType.NVarChar).Value = dwData["MSARWMONAT2"].ToString(); 
          or1.Parameters.Add("MSARWMONAT3", OracleType.NVarChar).Value = dwData["MSARWMONAT3"].ToString(); 
          or1.Parameters.Add("MSARWMONAT4", OracleType.NVarChar).Value = dwData["MSARWMONAT4"].ToString(); 
          or1.Parameters.Add("MSARWMONAT5", OracleType.NVarChar).Value = dwData["MSARWMONAT5"].ToString(); 
          or1.Parameters.Add("MSARWPROZ1", OracleType.NVarChar).Value = dwData["MSARWPROZ1"].ToString(); 
          or1.Parameters.Add("MSARWPROZ2", OracleType.NVarChar).Value = dwData["MSARWPROZ2"].ToString(); 
          or1.Parameters.Add("MSARWPROZ3", OracleType.NVarChar).Value = dwData["MSARWPROZ3"].ToString(); 
          or1.Parameters.Add("MSARWPROZ4", OracleType.NVarChar).Value = dwData["MSARWPROZ4"].ToString(); 
          or1.Parameters.Add("MSARWPROZ5", OracleType.NVarChar).Value = dwData["MSARWPROZ5"].ToString(); 
          or1.Parameters.Add("MSAMINDALT", OracleType.NVarChar).Value = dwData["MSAMINDALT"].ToString(); 
          or1.Parameters.Add("MSAZEITRAUM", OracleType.NVarChar).Value = dwData["MSAZEITRAUM"].ToString(); 
          or1.Parameters.Add("MSAMANPROZ1", OracleType.NVarChar).Value = dwData["MSAMANPROZ1"].ToString(); 
          or1.Parameters.Add("MSAMANPROZ2", OracleType.NVarChar).Value = dwData["MSAMANPROZ2"].ToString(); 
          or1.Parameters.Add("MSAMANPROZ3", OracleType.NVarChar).Value = dwData["MSAMANPROZ3"].ToString(); 
          or1.Parameters.Add("MSAMANPROZ4", OracleType.NVarChar).Value = dwData["MSAMANPROZ4"].ToString(); 
          or1.Parameters.Add("MSAMANPROZ5", OracleType.NVarChar).Value = dwData["MSAMANPROZ5"].ToString(); 
          or1.Parameters.Add("MSAPROZVON1", OracleType.NVarChar).Value = dwData["MSAPROZVON1"].ToString(); 
          or1.Parameters.Add("MSAPROZVON2", OracleType.NVarChar).Value = dwData["MSAPROZVON2"].ToString(); 
          or1.Parameters.Add("MSAPROZVON3", OracleType.NVarChar).Value = dwData["MSAPROZVON3"].ToString(); 
          or1.Parameters.Add("MSAPROZBIS1", OracleType.NVarChar).Value = dwData["MSAPROZBIS1"].ToString(); 
          or1.Parameters.Add("MSAPROZBIS2", OracleType.NVarChar).Value = dwData["MSAPROZBIS2"].ToString(); 
          or1.Parameters.Add("MSAPROZBIS3", OracleType.NVarChar).Value = dwData["MSAPROZBIS3"].ToString(); 
          or1.Parameters.Add("MSAMEINST", OracleType.NVarChar).Value = dwData["MSAMEINST"].ToString(); 
          or1.Parameters.Add("MSAMBEWPR", OracleType.NVarChar).Value = dwData["MSAMBEWPR"].ToString(); 
          or1.Parameters.Add("MSAINVBEWPR", OracleType.NVarChar).Value = dwData["MSAINVBEWPR"].ToString(); 
          or1.Parameters.Add("MSAKZBS", OracleType.NVarChar).Value = dwData["MSAKZBS"].ToString(); 
          or1.Parameters.Add("MSAFILLER", OracleType.NVarChar).Value = dwData["MSAFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
